<?php
if (!$_GET['id']) {
    echo "Bad Request";
} else {
    $id = $_GET['id'];
//including header.php 
    include '../../include/header.php';
//including page.php (It is a class which contain functions)
    include '../../libraries/page.php';
    $page = new page();
    session_start();
    $userid = $_SESSION['adminid'];

//checking the session
    if (!$_SESSION['admin_username']) {
        header("location:login.php");
    }

    if ($_GET['q'] == 'logout') {
        $page->admin_logout();
        header("location:login.php");
    }

    //checking the data posted or not?
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
// for $_POST['submit'].  Remember, field names are determined by array keys!
        $result = $page->mysql_update_array("users", $id, "userid", $_POST);
        if ($result) {
            $msg = $message[3];
        } else {
            $msg = $message[0];
        }
    }
    ?>

    <!--------------------------------------------------content----------------------------------->

    <!-------------------------------------Navbar---------------------------------->
    <div class="navbar">
        <div class="navbar-inner">
            <ul class="nav">
                <li><a href="index"><b style="font-size: 18px;margin-left: 30px">Admin</b></a></li>
        <!----  <li><a href="groups">Groups</a></li>
                <li><a href="../products/products">Products</a></li>
                <li><a href="../suppliers/suppliers">Suppliers</a></li>--->
            </ul>
            <a class="brand" href="../index"  id="right_title"><b style="color:#333;">Inventory</b></a>
            <i class="icon-home" id ="right"></i>
        </div>
    </div>
    <div style="float:right; margin-right:30px"> <a href="?q=logout">Log out</a></div>

    <!----------------------------------Display the result message of Update--------------------->
    <div  align="center"><? echo $msg; ?></div>

    <!----------------------------------------------div for placing form here------------------------->
    <div class="span4" style="height:300px; min-width: 230px;  margin-left: 40%; margin-top: 50px;">
        <h3 style="color:#777;margin-left: 25%;"> Update user</h3>
        <br />

        <!-----------------We are retrieving data from database table to display in the fields to update--------->
        <?
        //php code to get the data from groups table 
        $users = mysql_query("select * from users where userid = $id");
        $users_data = mysql_fetch_array($users);

        $usersid = $users_data['userid'];
        $name = $users_data['username'];
         $password = $users_data['password'];
          $email = $users_data['email'];
           $randomcode = $users_data['randomcode'];
           $active = $users_data['active'];
        
        ?>

        <?
        //date_default_timezone_set('Asia/Calcutta');
       // $date1 = date("d-m-Y H:i:s");
        ?>


        <!---------------------------------form------------------------------------------------>
        <form method="POST"  action="">
            <label>Username</label>
            <input class="input-xlarge" id="focusedInput" type="text" name="username" value="<? echo $name; ?>"  required>
             <label>password</label>
            <input class="input-xlarge" id="focusedInput" type="text" name="password" value="<? echo $password; ?>"  required>
             <label>Email</label>
            <input class="input-xlarge" id="focusedInput" type="text" name="email" value="<? echo $email; ?>"  required>
             <label>Random code</label>
            <input class="input-xlarge" id="focusedInput" type="text" name="randomcode" value="<? echo $randomcode; ?>"  required>
             <label>Active</label>
            <input class="input-xlarge" id="focusedInput" type="text" name="active" value="<? echo $active; ?>"  required>
           
            <button class="btn btn-inverse" type="submit"   style="float:right; margin-right: 15px; margin-top: 20px;">Update</button> 
        </form>
    </div>

    <?php
//including footer.php
    include '../../include/footer.php';
    ?>
    <?php
//closing the first else conditon 
}
?>